﻿using NewWms.ViewModels;
using NewWms.ViewModels.DialogsModel;
using NewWms.Views;
using NewWms.Views.Dialogs;
using Prism.DryIoc;
using Prism.Ioc;
using Prism.Services.Dialogs;
using System.Windows;
using wms_wpf.ViewModels;
using wms_wpf.Views;

namespace NewWms
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : PrismApplication
    {
        protected override Window CreateShell()
        {
            return Container.Resolve<MainWindow>();
        }
        private static System.Threading.Mutex mutex;
        protected override void OnStartup(StartupEventArgs e)
        {
            mutex = new System.Threading.Mutex(true, "WcsZz");
            if (mutex.WaitOne(0, false))
            {
                base.OnStartup(e);
            }
            else
            {
                MessageBox.Show("程序已经在运行！", "提示");
                this.Shutdown();
            }
        }
        protected override void OnInitialized()
        {

            var dialog = Container.Resolve<IDialogService>();
            dialog.ShowDialog("LoginView", callback =>
            {
                if (callback.Result == ButtonResult.None)
                {
                    Application.Current.Shutdown();
                    return;
                }
                if (callback.Result != ButtonResult.OK)
                {
                    return;
                }

            });
            base.OnInitialized();
        }
        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterForNavigation<MainWindow, MainWindowModel>();//注册view和viewmodel
            containerRegistry.RegisterForNavigation<MaterialView, MaterialViewModel>("MaterialView");
            containerRegistry.RegisterForNavigation<BoxConfigView, BoxConfigViewModel>("BoxConfigView");
            containerRegistry.RegisterForNavigation<UpAndDownShelvesView, UpAndDownShelvesViewModel>("UpAndDownShelvesView");
            containerRegistry.RegisterForNavigation<BoxShelfView, BoxShelfViewModel>("BoxShelfView");
            containerRegistry.RegisterForNavigation<WarehouseConfigView, WarehouseConfigViewModel>("WarehouseConfigView");
            containerRegistry.RegisterForNavigation<ShelfManageView, ShelfManageViewModel>("ShelfManageView");
            containerRegistry.RegisterForNavigation<InventorydetailsView, InventorydetailsViewModel>("InventorydetailsView");
            containerRegistry.RegisterForNavigation<RecordView, RecordViewViewModel>("RecordView");
            containerRegistry.RegisterForNavigation<LogNoteView, LogNoteViewModel>("LogNoteView");
            containerRegistry.RegisterForNavigation<MaterialBaseView, MaterialBaseViewMode>("MaterialBaseView");

            containerRegistry.RegisterDialog<CreateBoxsDialog, CreateBoxsDialogModel>("CreateBoxsDialog");
            containerRegistry.RegisterDialog<CreateWarehouseDialog, CreateWarehouseDialogModel>("CreateWarehouseDialog");
            containerRegistry.RegisterDialog<LoginView, LoginViewModel>();
            containerRegistry.RegisterDialog<UpdateBoxDialog, UpdateBoxDialogModel>("UpdateBoxDialog");
            containerRegistry.RegisterDialog<CreateMaterialPropertyDialog, CreateMaterialPropertyDialogModel>("CreateMaterialPropertyDialog");
        }
    }

}
